package cn.myzf.fort.access.accesscommon.processoutput.output;



import cn.myzf.fort.access.accesscommon.processoutput.core.StreamingProcessOwner;
import cn.myzf.fort.access.accesscommon.processoutput.reader.StreamingProcessReader;

import java.io.IOException;

public class StreamingProcessOutput
        extends AbstractProcessOutput {

    private static final long serialVersionUID = 3891848111786764283L;

    /** the owner. */
    protected StreamingProcessOwner m_Owner;

    /**
     * Initializes the process output with the specified owning object.
     *
     * @param owner	the owning object
     */
    public StreamingProcessOutput(StreamingProcessOwner owner) {
        super();
        m_Owner = owner;
    }

    /**
     * Configures the thread for stderr.
     *
     * @param process 	the process to monitor
     * @return		the configured thread, not yet started
     */
    @Override
    protected Thread configureStdErr(Process process) {
        return new Thread(new StreamingProcessReader(m_Owner, process, false));
    }

    /**
     * Configures the thread for stdout.
     *
     * @param process 	the process to monitor
     * @return		the configured thread, not yet started
     */
    @Override
    protected Thread configureStdOut(Process process) throws IOException {
        return new Thread(new StreamingProcessReader(m_Owner, process, true));
    }
}